package com.qf.service.Impl;

import com.qf.mapper.DeviceMapper;
import com.qf.mapper.DeviceTypeMapper;
import com.qf.model.Device;
import com.qf.model.DeviceType;
import com.qf.page.PageResult;
import com.qf.page.QueryPageBean;
import com.qf.service.DeviceService;
import com.qf.service.DeviceTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class DeviceTypeServiceImpl implements DeviceTypeService {
    @Autowired
    private DeviceTypeMapper deviceTypeMapper;

    @Override
    public List<DeviceType> findAll() {
        List<DeviceType> list = deviceTypeMapper.getAll();
        return list;
    }

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        //         total总记录数
//         rows当前页结果
        PageResult pageResult =new PageResult();
        Integer currentPage = queryPageBean.getCurrentPage();//当前页
        Integer pageSize = queryPageBean.getPageSize();//每页大小
        List<DeviceType> page = deviceTypeMapper.findPage((currentPage-1)*pageSize,pageSize);
        long count = deviceTypeMapper.count();
        pageResult.setRows(page);
        pageResult.setTotal(count);
        return pageResult;
    }

    @Override
    public int addDeviceType(DeviceType deviceType) {
        deviceType.setUpdatetime(new Date());
        int row = deviceTypeMapper.insertDeviceType(deviceType);
        return row;
    }

    @Override
    public DeviceType findById(int id) {
        DeviceType deviceType = deviceTypeMapper.findDeviceType(id);
        return deviceType;
    }

    @Override
    public int edit(DeviceType deviceType) {
        deviceType.setCreatetime(new Date());
        deviceType.setUpdatetime(new Date());
        int row = deviceTypeMapper.update(deviceType);
        return row;
    }

    @Override
    public int deleteById(Integer id) {
        int row = deviceTypeMapper.delDeviceType(id);
        return row;
    }
}